﻿@{
    ViewBag.Title = "";
    var id = Model != null ? Model.ID : 0;
}
@using ZBJF.Warranty.BLL
@using ZBJF.Warranty.WebProvider
@model ZBJF.Warranty.Model.ServiceProvider
<ul class="nav nav-tabs">
    <li><a href="/ServiceProvider/ServiceProviderIndex">服务商列表</a></li>
    <li class="active"><a href="/ServiceProvider/ServiceProviderEdit/@id">@(id > 0 ? "编辑服务商" : "添加服务商")</a></li>
</ul>
@using (Html.BeginForm("SaveServiceProvider", "ServiceProvider", FormMethod.Post, new { id = "inputForm", name = "inputForm", @class = "form-horizontal", enctype = "multipart/form-data" }))
{
    @Html.AntiForgeryToken()
    @Html.HiddenFor(c => c.ID)
    <div class="control-group">
        <label class="control-label">服务商名称：</label>
        <div class="controls">
            @Html.TextBoxFor(m => m.ServiceProviderName, new {validate = "{required:true,messages:{required:'请输入服务商名称'}}", maxLength = 50})
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">服务商类型：</label>
        <div class="controls">
            @{ bool staus = true;}
            @foreach (var item in ConvertToSelector.Instance.EnumTypeConvertToSelectList(typeof(ZBJF.Warranty.Common.Enums.Base.ServiceProductType)))
            {
                staus = false;
                if (item.Value != "")
                {
                    if (Model != null && Model.ServiceProviderType != null)
                    {
                        staus = Model.ServiceProviderType.Any(o => o.ServiceProviderTypeCode.ToString() == item.Value);
                    }
                    <input name="ServiceProviderType" class="ServiceProviderType" type="checkbox" value="@item.Value" @(staus ? "checked = true" : "")>@item.Text
                }
            }
            <input type="text" readonly class="virHidden" id="virHidden" validate="{required:true,messages:{required:'请选择服务商类型'}}" value="@(Model != null && Model.ServiceProviderType!= null?"1":"")" />
        </div>
    </div>
       <div class="control-group">
        <label class="control-label">账户名称：</label>
        <div class="controls">
            @Html.TextBoxFor(m => m.BankName, new { validate = "{required:true,messages:{required:'请输入账户名称'}}", maxLength = 50 })
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">开户行：</label>
        <div class="controls">
            @Html.TextBoxFor(m => m.BankAccountName, new { validate = "{required:true,messages:{required:'请输入开户行'}}", maxLength = 50 })
        </div>
    </div>
       <div class="control-group">
        <label class="control-label">账号：</label>
        <div class="controls">
            @Html.TextBoxFor(m => m.BankAccount, new { validate = "{required:true,messages:{required:'请输入账号'}}", maxLength = 50 })
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">联系电话：</label>
        <div class="controls">
            @Html.TextBoxFor(m => m.ContactPhone, new { validate = "{required:true,messages:{required:'请输入联系电话'}}", maxLength = 15 })
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">电子邮箱：</label>
        <div class="controls">
            @Html.TextBoxFor(m => m.ContactEmail, new { validate = "{email:true}", maxLength = 100 })
        </div>
    </div>
    <div class="control-group">
        <label class="control-label"></label>
        <div class="controls">
            <label>
                @Html.CheckBox("IsAvailable", Model != null ? Model.IsAvailable : true)
                是否可用
            </label>
        </div>
    </div>
    <div class="form-actions">
        <input id="btnSubmit" class="btn btn-primary Edit-R" type="button" value="保存" onclick="loading(this)">
        <input id="btnCancel" class="btn" type="button" value="重置" onclick="reset()">
    </div>
}
@section scripts{
    <script>
        $(function () {

            //选择服务商网点
            $(".ServiceProviderType").on("click", function () {
                var _v = $($(".ServiceProviderType:checked")[0]).val() || "";
                $("#virHidden").val(_v);
            })
        })
        function reset() {
            document.getElementById("inputForm").reset();
        }
        function loading(_this) {
            if ($("#inputForm").valid()) {
                _this.disabled = 'disabled';
                document.getElementById("inputForm").submit();
            }
        }
    </script>
}